package com.qfjy.homework.fanbenpeng;

import java.util.ArrayList;
import java.util.List;

/**
 * @author:fanbenpeng
 * @date:2022/11/10 19:33
 */
public class Main {
    public static void main(String[] args) {
        List<Person> persons = getPerson();

        //男性
        Criteria male = new CriteriaMale();
        //单身
        Criteria single = new CriteriaSingle();
        //女性
        CriteriaFemale criteriaFemale = new CriteriaFemale();
        //交集  单身男性
        AndCriteria andCriteria = new AndCriteria(single, male);
        //并集  单身或者男性
        OrCriteria orCriteria = new OrCriteria(single, male);

        printPersons("女性: ", criteriaFemale.meetCriteria(persons));
        printPersons("单身: ", single.meetCriteria(persons));
        printPersons("单身男性: ", andCriteria.meetCriteria(persons));
        printPersons("单身或是男性: ", orCriteria.meetCriteria(persons));
    }

    /**
     * 初始化用户类
     */
    private static List<Person> getPerson() {
        List<Person> persons = new ArrayList<>();
        persons.add(new Person("Robert", "男", "单身"));
        persons.add(new Person("John", "男", "结婚"));
        persons.add(new Person("Laura", "女", "结婚"));
        persons.add(new Person("Diana", "女", "单身"));
        persons.add(new Person("Mike", "男", "单身"));
        persons.add(new Person("Bobby", "男", "单身"));
        return persons;
    }

    /**
     * 输出集合
     *
     * @param persons 集合
     */
    public static void printPersons(String name, List<Person> persons) {
        System.out.println(name);
        persons.forEach(person ->
                System.out.println(person.toString())
        );
    }
}
